﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SiteFox.Business.Manager
{
    public static class QuickLinks
    {
        public static IList<Model.QuickLinks> GetAll()
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.QuickLinks select c;
            return _Query.ToList();
        }
        public static Model.QuickLinks GetByID(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.QuickLinks where c.ID == _ID select c;
            if (_Query.Count() > 0)
            {
                return _Query.Single();
            }
            else 
            {
                return null;
            }
        }
        public static void Create(Model.QuickLinks _QuickLinks)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            _Entities.AddToQuickLinks(_QuickLinks);
            _Entities.SaveChanges();
        }
        public static void Edit(Model.QuickLinks _QuickLinks)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.QuickLinks where c.ID == _QuickLinks.ID select c;
            var __QuickLinks = _Query.Single();
            __QuickLinks.Active = _QuickLinks.Active;
            __QuickLinks.Created = _QuickLinks.Created;
            __QuickLinks.CreatedBy = _QuickLinks.CreatedBy;
            __QuickLinks.Description = _QuickLinks.Description;
            __QuickLinks.Modified = _QuickLinks.Modified;
            __QuickLinks.ModifiedBy = _QuickLinks.ModifiedBy;
            __QuickLinks.Name = _QuickLinks.Name;
            _Entities.SaveChanges();
        }
        public static void Delete(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.QuickLinks where c.ID == _ID select c;
            var _QuickLinks = _Query.First();
            var _QuickLinkList = SiteFox.Business.Manager.QuickLink.GetByQuickLinks(_ID);
            for (int i = 0; i < _QuickLinkList.Count; i++) 
            {
                var _QuickLinkListItem = _QuickLinkList[i];
                SiteFox.Business.Manager.QuickLink.Delete(_QuickLinkListItem.ID);
            }
            _Entities.QuickLinks.DeleteObject(_QuickLinks);
            _Entities.SaveChanges();
        }
    }
}
